//
//  YYSeraviceVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/8/1.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYSeraviceVC.h"
#import "YYSeraviceCell.h"
#import "YYSeverModel.h"
#import "YYSeraviceDetailVC.h"

@interface YYSeraviceVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong)NSArray * dataArr;

@end

@implementation YYSeraviceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getData];
    }];
}

- (void)getData{
    [RequestOperationManager serviceList_Success:^(id result) {
        [self.tableView.mj_header endRefreshing];
        if (DEF_REQ_SUCCESS) {
        self.dataArr = [MTLJSONAdapter modelsOfClass:[YYSeverModel class] fromJSONArray:result[@"data"] error:nil];
            [self.tableView reloadData];
        }
    } failture:^(NSError *error) {
[self.tableView.mj_header endRefreshing];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YYSeraviceCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YYSeraviceCell"];
    cell.model = self.dataArr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    YYSeraviceDetailVC * detail = (YYSeraviceDetailVC*)[CFUtility getVC:@"YYSeraviceDetailVC" Storyboard:SERAVICE];
    YYSeverModel * model = self.dataArr[indexPath.row];
    detail.sid = model.selid;
    [self.navigationController pushViewController:detail animated:YES];
}


-(NSArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataArr;
}


@end
